//
//  MoneyViewController.m
//  zuixin
//
//  Created by QJY on 14-8-18.
//  Copyright (c) 2014年 dingshenwangluokeji. All rights reserved.
//

#import "MoneyViewController.h"
#import "Header.h"
#import "NetAccess.h"
#import "MBProgressHUD.h"
#import "AFNetworking.h"
#import "AFHTTPRequestOperation.h"
#import "ChongzhiViewController.h"
#import "LeHuViewController.h"
#import "Base64Encry.h"
@interface MoneyViewController ()<UITextFieldDelegate>
//<UITableViewDataSource,UITableViewDelegate>

@end

@implementation MoneyViewController
{
//    UITextField *_field;
//    UITextField *_field1;
//    UITextField *_field2;
//     UITextField *_field3;
//    UITextField *_field4;
//    NSMutableData *_data;
   UIAlertView *_alertView;
//    NSString * _string;
    MBProgressHUD *pro;
    NSArray*_commodityArry;
    NSArray*_detailArry;
    NSArray*_imageArry;
    UIImageView*_imgV;
    NSString*str ;
    UITextField*field1;
    UITextField*field2;
    UILabel*label2;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
//使用MB效果图
//-(void)match
//{
//    pro = [[MBProgressHUD alloc] initWithView:self.view];
//    pro.labelText = @"正在加载中..";
//    pro.mode = MBProgressHUDModeText;
//    [self.view addSubview:pro];
//    [pro showAnimated:YES whileExecutingBlock:^{
//        [NSThread sleepForTimeInterval:20.0];
//    } completionBlock:^{
//    }];
//}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
//    _field.text =nil;
//    _field1.text =nil;
//    _field2.text =nil;
//    _field3.text =nil;
//    _field4.text =nil;
//    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title =@"充值";
    self.view.backgroundColor=[UIColor colorWithRed:246.0/255 green:247.0/255 blue:248.0/255 alpha:1] ;
    if (IOS7) {
        self.edgesForExtendedLayout=NO;
    }

    [self setNavigationBar];
    //[self addBack];
    [self addImageView];
    [self addLabel];
    //[self addTabView];
   
    
}
//返回
-(void)addBack
{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 28, 28);
    
    [backBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;
    
    // Do any additional setup after loading the view.

}
-(void)doBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)setNavigationBar
{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navgationbar.png"] forBarMetrics: UIBarMetricsDefault];
    NSDictionary *navTitleArr = [NSDictionary dictionaryWithObjectsAndKeys:
                                 //title字体－title字体颜色
                                 [UIFont boldSystemFontOfSize:23],UITextAttributeFont,
                                 [UIColor whiteColor],UITextAttributeTextColor ,nil];
    [self.navigationController.navigationBar setTitleTextAttributes:navTitleArr];
}
-(void)addImageView
{
    if(DeviceHeight==568)
    {
    _imgV=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 130)];
        _imgV.image=[UIImage imageNamed:@"imagecenter.jpg"];
        [self.view addSubview:_imgV];
        UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 130)];
        [_imgV addSubview:label1];
        
        NSArray *array =[[NSUserDefaults standardUserDefaults] objectForKey:@"newusers1"];
        
        NSDictionary *dict =[array objectAtIndex:0];
        
        str =[dict objectForKey:@"username"];
        
             label1.text=[NSString stringWithFormat:@"充值账号:%@",str];
        label1.font=[UIFont systemFontOfSize:18];
        label1.textAlignment=NSTextAlignmentCenter;
        label1.textColor=[UIColor whiteColor];
        label1.backgroundColor=[UIColor clearColor];
        
        
        
        label2=[[UILabel alloc]initWithFrame:CGRectMake(0, 40, 320, 80)];
       // [_imgV addSubview:label2];
        label2.text=@"充值成功后，请在广场查询余额";
        label2.backgroundColor=[UIColor clearColor];
        label2.font=[UIFont systemFontOfSize:25];
        //label2.adjustsFontSizeToFitWidth=YES;
        label2.textAlignment=UITextAlignmentCenter;
        label2.textColor=[UIColor whiteColor];
        
    }
    else
    {
        _imgV=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 80)];
     _imgV.image=[UIImage imageNamed:@"imagecenter.jpg"];
    [self.view addSubview:_imgV];
    UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 80)];
    [_imgV addSubview:label1];
        NSArray *array =[[NSUserDefaults standardUserDefaults] objectForKey:@"newusers1"];
        NSLog(@"nihawohao %@",array);
        NSDictionary *dict =[array objectAtIndex:0];
        
        str =[dict objectForKey:@"username"];
    //NSString*str=@"1223552";
    // label1.backgroundColor=[UIColor redColor];
    label1.text=[NSString stringWithFormat:@"充值账号:%@",str];
    label1.font=[UIFont systemFontOfSize:17];
    label1.textAlignment=NSTextAlignmentCenter;
    label1.textColor=[UIColor whiteColor];
    label1.backgroundColor=[UIColor clearColor];
    
    
    
    label2=[[UILabel alloc]initWithFrame:CGRectMake(0, 30, 320, 60)];
    label2.backgroundColor=[UIColor clearColor];
    //[_imgV addSubview:label2];
    label2.text=@"充值成功后，请在广场查询余额";
        
    //label2.adjustsFontSizeToFitWidth=YES;
        label2.font=[UIFont systemFontOfSize:20];
    label2.textAlignment=UITextAlignmentCenter;
    label2.textColor=[UIColor whiteColor];
    }
    if(DeviceHeight==568)
    {
        UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(250, 130, 60, 40);
        [button setBackgroundImage:[UIImage imageNamed:@"instructions.png"] forState:UIControlStateNormal];
        [self.view addSubview:button];
    }
    else
    {
        UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];button.frame=CGRectMake(250, 80, 60, 30);
        [button setBackgroundImage:[UIImage imageNamed:@"instructions.png"] forState:UIControlStateNormal];
        [self.view addSubview:button];
    }

    
}
-(void)addLabel
{
    if (DeviceHeight==568) {
        UILabel*label3=[[UILabel alloc]initWithFrame:CGRectMake(10, 150, 300, 40)];
        label3.backgroundColor=[UIColor clearColor];
        [self.view addSubview:label3];
        
        field1=[[UITextField alloc]initWithFrame:CGRectMake(10, 190, 300, 40)];
        field1.background=[UIImage imageNamed:@"beijingkuang2"];
        field1.keyboardType=UIKeyboardTypeNumberPad;
        label3.text=[NSString stringWithFormat:@"充值卡序列号"];
        field1.delegate=self;
        [self.view addSubview:field1];
        
        UITextField* field=[[UITextField alloc]initWithFrame:CGRectMake(10, 230, 300, 40)];
        UILabel*label4=[[UILabel alloc]initWithFrame:CGRectMake(10, 230, 300, 40)];
        //field.background=[UIImage imageNamed:@"beijingkuang2"];
        [self.view addSubview:field];
        
        label4.text=[NSString stringWithFormat:@"充值卡密码"];
        label4.backgroundColor=[UIColor clearColor];
        [self.view addSubview:label4];
        field2=[[UITextField alloc]initWithFrame:CGRectMake(10, 270, 300, 40)];
        field2.background=[UIImage imageNamed:@"beijingkuang2"];
        field2.delegate=self;
        
        field2.keyboardType=UIKeyboardTypeNumberPad;
        [self.view addSubview:field2];
        UITextField* field3=[[UITextField alloc]initWithFrame:CGRectMake(10, 310, 300, 40)];
        // field3.background=[UIImage imageNamed:@"beijingkuang2"];
        [self.view addSubview:field3];
        field3.userInteractionEnabled=NO;
        field.userInteractionEnabled=NO;
        field.backgroundColor=[UIColor colorWithRed:246.0/255 green:247.0/255 blue:248.0/255 alpha:1] ;
        field3.backgroundColor=[UIColor colorWithRed:246.0/255 green:247.0/255 blue:248.0/255 alpha:1] ;
        // field3.backgroundColor=[UIColor redColor];
        UIButton*btn=[UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame=CGRectMake(50, 330, 220, 40);
        [btn setTitle:@"确认充值" forState:UIControlStateNormal];
        btn.titleLabel.textAlignment=1;
        //btn.backgroundColor=[UIColor colorWithWhite:0.8 alpha:1];
        btn.backgroundColor=[UIColor colorWithRed:0.2f green:0.6f blue:0.9f alpha:1];
        [btn addTarget:self action:@selector(tap) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
    else
    {
UILabel*label3=[[UILabel alloc]initWithFrame:CGRectMake(10, 90, 300, 40)];
label3.backgroundColor=[UIColor clearColor];
[self.view addSubview:label3];

field1=[[UITextField alloc]initWithFrame:CGRectMake(10, 130, 300, 40)];
field1.background=[UIImage imageNamed:@"beijingkuang2"];
field1.keyboardType=UIKeyboardTypeNumberPad;
label3.text=[NSString stringWithFormat:@"充值卡序列号"];
field1.delegate=self;
[self.view addSubview:field1];

UITextField* field=[[UITextField alloc]initWithFrame:CGRectMake(10, 170, 300, 40)];
UILabel*label4=[[UILabel alloc]initWithFrame:CGRectMake(10, 170, 300, 40)];
label4.backgroundColor=[UIColor clearColor];
//field.background=[UIImage imageNamed:@"beijingkuang2"];
[self.view addSubview:field];

label4.text=[NSString stringWithFormat:@"充值卡密码"];
[self.view addSubview:label4];
field2=[[UITextField alloc]initWithFrame:CGRectMake(10, 210, 300, 40)];
field2.background=[UIImage imageNamed:@"beijingkuang2"];
field2.delegate=self;

field2.keyboardType=UIKeyboardTypeNumberPad;
[self.view addSubview:field2];
UITextField* field3=[[UITextField alloc]initWithFrame:CGRectMake(10, 250, 300, 40)];
// field3.background=[UIImage imageNamed:@"beijingkuang2"];
[self.view addSubview:field3];
field3.userInteractionEnabled=NO;
field.userInteractionEnabled=NO;
field.backgroundColor=[UIColor colorWithRed:246.0/255 green:247.0/255 blue:248.0/255 alpha:1] ;
field3.backgroundColor=[UIColor colorWithRed:246.0/255 green:247.0/255 blue:248.0/255 alpha:1] ;
// field3.backgroundColor=[UIColor redColor];
UIButton*btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(50, 270, 220, 40);
[btn setTitle:@"确认充值" forState:UIControlStateNormal];
btn.titleLabel.textAlignment=1;
 btn.backgroundColor=[UIColor colorWithRed:0.2f green:0.6f blue:0.9f alpha:1];
[btn addTarget:self action:@selector(tap) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];

// Do any additional setup after loading the view.
}
}
-(void)tap
{
    
    
    NetAccess *net =[NetAccess sharedNetAccess];
    if(![net haveNet])
    {
        
        UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"无网络连接" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
        
        
        
    }
    else
    {
        if (IOS5) {
            if (!(field1.text||field2.text))
            {
              
                _alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"充值卡序列号或者密码为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                [_alertView show];
            }
            else{
                [self getShuJu];
            }
        }
        else
        {
            
            if ([field2.text isEqualToString:@""]||[field1.text isEqualToString:@""])
            {
               
                _alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"充值卡序列号或者密码为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                
                [_alertView show];
                
            }
            else
            {
                [self getShuJu];
            }
        }}
}

-(void)getShuJu
{
    pro=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
//           NSString *str1=[NSString stringWithFormat:@"http://oemapi2.leehuu.cn/api/vos/UsePrepaidCard2?userName=%@&cardNumber=%@&cardPassword=%@&parent=62634",str,field1.text,field2.text];
//  
//        NSURL *url = [NSURL URLWithString:[str1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//        NSURLRequest *request = [NSURLRequest requestWithURL:url];
//        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
//        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//            NSString *html = operation.responseString;
//            NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
//            if (data==nil) {
//                [pro removeFromSuperview];
//                UIAlertView*aler=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"服务暂不可用，请稍后再试" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
//                [aler show];
//            }
//            else
//            {
//                id  dict=[NSJSONSerialization  JSONObjectWithData:data options:0 error:nil];
    NSString*urlStr=@"http://oemapi2.leehuu.cn/YXBp/dm9zb2Vt/VXNlUHJlcGFpZENhcmQy";
    NSString * parameterStr=[NSString stringWithFormat:@"dXNlck5hbWUPQ=%@&cardNumber=%@&cardPassword=%@&parent=2645421",[Base64Encry switchBase64String:str],field1.text,field2.text];
    NSLog(@"登录%@",[NSString stringWithFormat:@"%@  %@",urlStr,parameterStr]);
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        id dict=[Base64Encry switchUrlString:urlStr switchParameterString:parameterStr];
        if([dict count])
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"获取到的数据为1：%@",dict);
                
                NSString* excString=[dict objectForKey:@"exception"];
                NSString* retString=[dict objectForKey:@"retCode"];
                
                NSString *message = @"充值成功，请在广场查询余额";
                if ([retString intValue])
                {
                    [pro removeFromSuperview];
                    message=excString;
                    _alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                    
                    [_alertView show];
                    return;
                }
                else
                    //信息正确
                {
                    [pro removeFromSuperview];
                    _alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                    
                    [_alertView show];
                    
                }
                
            });
        }
    });
    

                }
          
//        }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//             [pro removeFromSuperview];
//            UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"网络繁忙，请稍后尝试" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//            [alert show];
//          
//        }];
//        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
//        [queue addOperation:operation];
//    }
//


-(void)addTabView
{
    UITableView*tab=[[UITableView alloc]initWithFrame:CGRectMake(0, 80, 320, DeviceHeight-80-64)style:UITableViewStyleGrouped];
   // tab.delegate=self;
   // tab.dataSource=self;
    if(DeviceHeight==568)
    {
    UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(250, -2, 60, 40);
    [button setBackgroundImage:[UIImage imageNamed:@"instructions.png"] forState:UIControlStateNormal];
    [tab addSubview:button];
    }
    else
    {
        UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];button.frame=CGRectMake(250, 2, 60, 30);
        [button setBackgroundImage:[UIImage imageNamed:@"instructions.png"] forState:UIControlStateNormal];
        [tab addSubview:button];
    }
    
    
    
    
    [self.view addSubview:tab];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [field2 resignFirstResponder];
    [field1 resignFirstResponder];
    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    
    
    return YES;
}
//键盘上下移动
-(void)textFieldDidBeginEditing:(UITextField *)textField{   //开始编辑时，整体上移
    //    if (textField.tag==0) {
    //        [self moveView:-20];
    //    }
    //    if (textField.tag==1)
    //    {
    [self moveView:-40];
    //    }
}
-(void)textFieldDidEndEditing:(UITextField *)textField{     //结束编辑时，整体下移
    //    if (textField.tag==0) {
    //        [self moveView:20];
    //    }
    //    if (textField.tag==1)
    //    {
    [self moveView:40];
    //    }
}
-(void)moveView:(float)move{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    frame.origin.y+=move;//view的X轴上移
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeView" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];//设置调整界面的动画效果
    
    
}

#pragma --tabView基本知识

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(DeviceHeight==568)
    {    return 80;
    }
    else
    {
    return 60;
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [_detailArry count];
}
-(float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString*reuseIdetify=@"cell";
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:reuseIdetify];
    if (!cell)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdetify];
    }
    UIImageView*imagv=[[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"price%d.png",indexPath.section]]];
    if (DeviceHeight==568) {
    imagv.frame=CGRectMake(20, 0, 60, 80);
        UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(80, 15, 200, 30)];
        label.text=_commodityArry[indexPath.section];
        //label.font=[UIFont fontWithName:@"Courier-Bold" size:22];
        label.font=[UIFont systemFontOfSize:23];
        [cell addSubview:label];
        
        UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(80, 45, 200, 30)];
        label1.text=_detailArry[indexPath.section];
        label1.textColor=[UIColor grayColor];
        [cell addSubview:label1];
    }
    else
    {
      imagv.frame=CGRectMake(20, 0, 50, 60);
        UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(70, 5, 200, 25)];
        label.text=_commodityArry[indexPath.section];
        //label.font=[UIFont fontWithName:@"Courier-Bold" size:22];
        label.font=[UIFont systemFontOfSize:22];
        [cell addSubview:label];
        
        UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(70, 30, 200, 25)];
        label1.text=_detailArry[indexPath.section];
        label1.textColor=[UIColor grayColor];
        [cell addSubview:label1];
    }
    [cell addSubview:imagv];
    
    
    
    UIImageView *imgV=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"priceicon.png"]];
    imgV.frame=CGRectMake(0, 0, 30, 30);
    
   // [cell addSubview:imgV];
    cell.accessoryView=imgV;
    
    
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString*residentifier=@"cell";
    
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:residentifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:residentifier];
    }
    if (indexPath.section==0) {
        LeHuViewController*lehu=[[LeHuViewController alloc]init];
        lehu.str2=_commodityArry[0];
        lehu.str=str;
        [self.navigationController pushViewController:lehu animated:YES];
        
    }
    else
    {
    ChongzhiViewController*topup=[[ChongzhiViewController alloc]init];
    topup.str=[NSString stringWithFormat:@"充%@",_commodityArry[indexPath.section]];
    topup.str1=str;
    NSLog(@"你还%@%@",topup.str1,topup.str);
[self.navigationController pushViewController:topup animated:YES] ;
    }
}
//     self.view.backgroundColor =[UIColor whiteColor];
//    [self textfield];
//    UIImageView *imageView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"LOGO.png"]];
//    imageView.frame =CGRectMake(110, 70 ,90, 90);
//    [self.view addSubview:imageView];
//    
//    UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
//    btn .frame =CGRectMake(20, _field2.frame.size.height+270, 280, 40);
//    btn.backgroundColor =[UIColor colorWithRed:0.2f green:0.6f blue:0.9f alpha:1];
//    [btn setTitle:@"确定充值" forState:UIControlStateNormal];
//    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    btn.layer.cornerRadius =10;
//    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:btn];
//}
//-(void)bbiClick
//{
//    [self dismissViewControllerAnimated:YES completion:^{
//    }];
//}
//-(void)btnClick
//{
//    NSString *message = @"注册成功";
//    // 提示框
//    _alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
//    
//    if(_field.text.length <= 0)
//    {
//        message = @"亲！您的卡号不存在..";
//        _alertView.message = message;
//        // 显示提示框
//        [_alertView show];
//        return;
//    }
//    if(_field1.text.length <= 0)
//    {
//        message = @"亲~你的充值卡号输入不正确哦！";
//        _alertView.message = message;
//        [_alertView show];
//        return;
//    }
//    if(_field2.text.length <= 0)
//    {
//        message = @"亲~密码不正确哦！";
//        _alertView.message = message;
//        [_alertView show];
//        return;
//    }
//    if(_field.text.length>0&&_field1.text.length>0&&_field2.text.length>0)
//    {[self match];
//        NetAccess *net =[NetAccess sharedNetAccess];
//        if(![net haveNet])
//        {
//            UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"无网络连接" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//            [alertView show];
//        }else{
//            NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"http://api2.ixincall.com/vos/api/PayByPhoneCard?ownerName=%@&pin=%@&password=%@",_field.text,_field1.text,_field2.text]];
//            NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
//            NSURLConnection *connent =[[NSURLConnection alloc]initWithRequest:request delegate:self];
//            [connent start];
//        }
//        return;
//    }
//}
#pragma mark--网络代理方法
//-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
//{
//    _data =[[NSMutableData alloc]init];
//}
//-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
//{
//    [_data appendData:data];
//}
//-(void)connectionDidFinishLoading:(NSURLConnection *)connection
//{
//    _string =[[NSString alloc]initWithData:_data encoding:NSUTF8StringEncoding];
//    NSString *dce =[_string stringByReplacingOccurrencesOfString:@"{" withString:@""];
//    NSString *kuj =[dce stringByReplacingOccurrencesOfString:@"}" withString:@""];
//    NSArray *dfg =[kuj componentsSeparatedByString:@","];
//    _string =[dfg objectAtIndex:0];
//    if([_string hasPrefix:@"retCode:-10007"])
//    {[pro removeFromSuperview];
//        NSString *message =@"账号不存在或者密码错误";
//        _alertView.message = message;
//        [_alertView show];
//        return;
//    }
//    else if([_string hasPrefix:@"retCode:0"])
//    {
//        [pro removeFromSuperview];
//        NSString *message =@"充值成功";
//        _alertView.message = message;
//        [_alertView show];
//        return;
//    }
//}
//-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
//{[pro removeFromSuperview];
//    NSString *message =@"亲！网络不给力啊，稍后再试吧..!";
//    _alertView.message = message;
//    [_alertView show];
//}
//-(void)textfield
//{
//    _field =[[UITextField alloc]initWithFrame:CGRectMake(20,175, 320-40,35)];
//    _field.backgroundColor =[UIColor whiteColor];
//    _field.borderStyle = UITextBorderStyleRoundedRect;
//    _field.placeholder = @"手机号码:";
//     _field
//    .delegate =self;
//    [self.view addSubview:_field];
//    
//    _field1 =[[UITextField alloc]initWithFrame:CGRectMake(20,_field.frame.origin.y+45, 320-40,35)];
//    _field1.borderStyle =UITextBorderStyleRoundedRect;
//    _field1 .delegate =self;
//    _field1.placeholder = @"充值卡卡号:";
//    [self.view addSubview:_field1];
//    
//    _field2 =[[UITextField alloc]initWithFrame:CGRectMake(20,_field1.frame.origin.y+45, 320-40,35)];
//    _field2.delegate =self;
//    _field2.borderStyle =UITextBorderStyleRoundedRect;
//    _field2.secureTextEntry =YES;
//    _field2.placeholder = @"充值卡密码:";
//    [self.view addSubview:_field2];
//    [_field2 addTarget:self action:@selector(textFieldDidBeginEditing:) forControlEvents:UIControlEventEditingDidBegin];
//    [_field2 addTarget:self action:@selector(textFieldDidEndEditing:) forControlEvents:UIControlEventEditingDidEnd];
//}
//-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    [_field resignFirstResponder];
//    [_field1 resignFirstResponder];
//    [_field2 resignFirstResponder];
//}
//-(void)textFieldDidBeginEditing:(UITextField *)textField{   //开始编辑时，整体上移
//    //    if (textField.tag==0) {
//    //        [self moveView:-20];
//    //    }
//    //    if (textField.tag==1)
//    //    {
//    [self moveView:-60];
//    //    }
//}
//-(void)textFieldDidEndEditing:(UITextField *)textField{     //结束编辑时，整体下移
//    //    if (textField.tag==0) {
//    //        [self moveView:20];
//    //    }
//    //    if (textField.tag==1)
//    //    {
//    [self moveView:60];
//    //    }
//}
//-(void)moveView:(float)move{
//    NSTimeInterval animationDuration = 0.30f;
//    CGRect frame = self.view.frame;
//    frame.origin.y+=move;//view的X轴上移
//    self.view.frame = frame;
//    [UIView beginAnimations:@"ResizeView" context:nil];
//    [UIView setAnimationDuration:animationDuration];
//    self.view.frame = frame;
//    [UIView commitAnimations];//设置调整界面的动画效果
//    
//    
//}
//
//-(BOOL)textFieldShouldReturn:(UITextField *)textField
//{
//    [textField resignFirstResponder];
//    return YES;
//}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
